Page({
  data: {
    inputVal: '',
    msgData: []
  },
  changeInputVal(ev) {
    this.setData({
      inputVal: ev.detail.value
    });
  },
  delMsg(ev) {
    var n = ev.target.dataset.index;

    var list = this.data.msgData;
    list.splice(n, 1);

    this.setData({
      msgData: list
    });
  },
  addMsg() {
    //console.log(this.data.inputVal);
    // this.data.msgData.push({
    //   msg:this.data.inputVal
    // });
    if (this.data.inputVal == null || this.data.inputVal==""){
      wx.showToast({
        title: '留言为空，失败',
        icon:'loading',
        duration:2000
      })
      return false;
    } else if (this.data.inputVal.length>15){
      wx.showToast({
        title: '留言太长,失败',
        icon: 'loading',
        duration: 2000
      })
      return false;
    }
    var list = this.data.msgData;
    list.push({
      msg: this.data.inputVal
    });
    //更新
    this.setData({
      msgData: list,
      inputVal: ''
    });
  }
})
